<?php

/**
 * order actions.
 *
 * @package    visa
 * @subpackage order
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class orderActions extends sfActions
{
	/**
	* Executes index action
	*
	* @param sfRequest $request A request object
	*/
	public function executeIndex(sfWebRequest $request)
	{
		$this->forward('default', 'module');
	}
	
	public function executeList(sfWebRequest $request)
  	{
		// UPDATE STATUS
		$func = $request->getParameter("func");
		if (isset($func) && $func == "update") {
			$q = Doctrine_Query::create()
					->from("VTNSOrder o");
			foreach ($q->fetchArray() as $order_to_change) {
				$order_to_change_status = $request->getParameter("order_status_".$order_to_change['order_id']);
				if (isset($order_to_change_status) && $order_to_change_status == "on") {
					$order_obj = Doctrine_Core::getTable("VTNSOrder")->find($order_to_change['order_id']);
					if ($order_obj->status == 0)
						$order_obj->status = 1;
					else
						$order_obj->status = 0;
					$order_obj->save();
				}
			}
		}
		
		$q = Doctrine_Query::create()
				->from("VTNSOrder o");
		$orders = $q->fetchArray();
		$orders_pending = array();
		$orders_success = array();
		foreach ($orders as $order)
		{
			if ($order['status'] == 0)
			  	$orders_pending[] = $order;
			else
			  	$orders_success[] = $order;
		}
		$this->orderListPending = $orders_pending;
		$this->orderListSuccess = $orders_success;
		
		return sfView::SUCCESS;
	}
	
	public function executeDetail(sfWebRequest $request)
  	{
		$order_id = (int)$request->getParameter("order_id");
		$order = Doctrine_Core::getTable("VTNSOrder")->find($order_id);
		
		$q = Doctrine_Query::create()
				->from("VTNSCustomer c")
				->where("c.order_id = ?", $order->order_id);
		$this->customers = $q->fetchArray();
	}
}
